<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>SSL证书 | KCloud-Platform-Alibaba</title>
    <meta name="generator" content="VuePress 1.9.2">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="一个基于VuePress的 知识管理&amp;博客 主题">
    <meta name="keywords" content="vuepress,theme,blog,vdoing">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.f1160bd0.css" as="style"><link rel="preload" href="/assets/js/app.c1130a26.js" as="script"><link rel="preload" href="/assets/js/2.4ec61f8d.js" as="script"><link rel="preload" href="/assets/js/17.f10e7f0d.js" as="script"><link rel="prefetch" href="/assets/js/10.e3efb9c9.js"><link rel="prefetch" href="/assets/js/11.215e8173.js"><link rel="prefetch" href="/assets/js/12.e49aaa47.js"><link rel="prefetch" href="/assets/js/13.c0cadd0c.js"><link rel="prefetch" href="/assets/js/14.354c04aa.js"><link rel="prefetch" href="/assets/js/15.0ccb9393.js"><link rel="prefetch" href="/assets/js/16.284febc7.js"><link rel="prefetch" href="/assets/js/18.3e728c4a.js"><link rel="prefetch" href="/assets/js/19.5a760622.js"><link rel="prefetch" href="/assets/js/3.cd68975a.js"><link rel="prefetch" href="/assets/js/4.1e281399.js"><link rel="prefetch" href="/assets/js/5.fa0f019a.js"><link rel="prefetch" href="/assets/js/6.d5489e3f.js"><link rel="prefetch" href="/assets/js/7.c3b0abd7.js"><link rel="prefetch" href="/assets/js/8.1acb47f0.js"><link rel="prefetch" href="/assets/js/9.e9e30dab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f1160bd0.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="KCloud-Platform-Alibaba" class="logo"> <span class="site-name can-hide">KCloud-Platform-Alibaba</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/a2f161/" class="nav-link">Centos7安装Mysql 8.0.33</a></li><li class="dropdown-subitem"><a href="/pages/90401a/" class="nav-link">Centos7安装Redis 7.0.11</a></li><li class="dropdown-subitem"><a href="/pages/0fb88c/" class="nav-link">Centos7安装RocketMQ 5.1.1</a></li><li class="dropdown-subitem"><a href="/pages/65acfd/" class="nav-link">Centos7安装Jdk 17.0.7</a></li><li class="dropdown-subitem"><a href="/pages/65acff/" class="nav-link">Centos7安装Docker 23.0.6</a></li><li class="dropdown-subitem"><a href="/pages/552b64/" class="nav-link">Docker安装RabbitMQ 3.12.2</a></li><li class="dropdown-subitem"><a href="/pages/d715cf/" class="nav-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></li><li class="dropdown-item"><h4>快速上手</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/10bfa2/" class="nav-link">一键部署</a></li><li class="dropdown-subitem"><a href="/pages/10bfa7/" class="nav-link">项目启动</a></li><li class="dropdown-subitem"><a href="/pages/192acb/" class="nav-link">API网关</a></li><li class="dropdown-subitem"><a href="/pages/36da89/" class="nav-link">认证授权</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务注册&amp;发现</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">配置中心</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式事务</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多级缓存</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据推送</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">消息队列</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务熔断&amp;降级</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">远程调用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">链路跟踪</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">对象存储</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">日志分析</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式锁</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务监控</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">读写分离&amp;分库分表</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多数据源</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据库版本控制</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">持续集成&amp;交付</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">自动化部署</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口幂等性</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口安全</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">XSS攻击</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">统计报表</a></li><li class="dropdown-subitem"><a href="/pages/10bfa8/" aria-current="page" class="nav-link router-link-exact-active router-link-active">SSL证书</a></li></ul></li><li class="dropdown-item"><h4>系统设计</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">高可用设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多租户设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">权限设计</a></li></ul></li><li class="dropdown-item"><h4>工具使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Git使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Maven使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Docker使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Jenkins使用</a></li></ul></li><li class="dropdown-item"><h4>第三方对接</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">微信公众号对接</a></li></ul></li><li class="dropdown-item"><h4>脚本使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Linux shell脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Lua脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Window bat脚本使用</a></li></ul></li><li class="dropdown-item"><h4>技术分享</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">RocketMQ的冒险之旅（先占占位置）</a></li></ul></li><li class="dropdown-item"><h4>架构演进</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">老寇云平台架构演进（先占占位置）</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/pages/1b12ed/" class="nav-link">赞助</a></div> <a href="https://github.com/KouShenhai/KCloud-Platform-Alibaba" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/a2f161/" class="nav-link">Centos7安装Mysql 8.0.33</a></li><li class="dropdown-subitem"><a href="/pages/90401a/" class="nav-link">Centos7安装Redis 7.0.11</a></li><li class="dropdown-subitem"><a href="/pages/0fb88c/" class="nav-link">Centos7安装RocketMQ 5.1.1</a></li><li class="dropdown-subitem"><a href="/pages/65acfd/" class="nav-link">Centos7安装Jdk 17.0.7</a></li><li class="dropdown-subitem"><a href="/pages/65acff/" class="nav-link">Centos7安装Docker 23.0.6</a></li><li class="dropdown-subitem"><a href="/pages/552b64/" class="nav-link">Docker安装RabbitMQ 3.12.2</a></li><li class="dropdown-subitem"><a href="/pages/d715cf/" class="nav-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></li><li class="dropdown-item"><h4>快速上手</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/10bfa2/" class="nav-link">一键部署</a></li><li class="dropdown-subitem"><a href="/pages/10bfa7/" class="nav-link">项目启动</a></li><li class="dropdown-subitem"><a href="/pages/192acb/" class="nav-link">API网关</a></li><li class="dropdown-subitem"><a href="/pages/36da89/" class="nav-link">认证授权</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务注册&amp;发现</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">配置中心</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式事务</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多级缓存</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据推送</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">消息队列</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务熔断&amp;降级</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">远程调用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">链路跟踪</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">对象存储</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">日志分析</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">分布式锁</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">服务监控</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">读写分离&amp;分库分表</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多数据源</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">数据库版本控制</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">持续集成&amp;交付</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">自动化部署</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口幂等性</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">接口安全</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">XSS攻击</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">统计报表</a></li><li class="dropdown-subitem"><a href="/pages/10bfa8/" aria-current="page" class="nav-link router-link-exact-active router-link-active">SSL证书</a></li></ul></li><li class="dropdown-item"><h4>系统设计</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">高可用设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">多租户设计</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">权限设计</a></li></ul></li><li class="dropdown-item"><h4>工具使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Git使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Maven使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Docker使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Jenkins使用</a></li></ul></li><li class="dropdown-item"><h4>第三方对接</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">微信公众号对接</a></li></ul></li><li class="dropdown-item"><h4>脚本使用</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">Linux shell脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Lua脚本使用</a></li><li class="dropdown-subitem"><a href="/" class="nav-link">Window bat脚本使用</a></li></ul></li><li class="dropdown-item"><h4>技术分享</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">RocketMQ的冒险之旅（先占占位置）</a></li></ul></li><li class="dropdown-item"><h4>架构演进</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/" class="nav-link">老寇云平台架构演进（先占占位置）</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/pages/1b12ed/" class="nav-link">赞助</a></div> <a href="https://github.com/KouShenhai/KCloud-Platform-Alibaba" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>环境搭建</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/a2f161/" class="sidebar-link">Centos7安装Mysql 8.0.33</a></li><li><a href="/pages/90401a/" class="sidebar-link">Centos7安装Redis 7.0.11</a></li><li><a href="/pages/0fb88c/" class="sidebar-link">Centos7安装RocketMQ 5.1.1</a></li><li><a href="/pages/65acfd/" class="sidebar-link">Centos7安装Jdk 17.0.7</a></li><li><a href="/pages/65acff/" class="sidebar-link">Centos7安装Docker 23.0.6</a></li><li><a href="/pages/552b64/" class="sidebar-link">Docker安装RabbitMQ 3.12.2</a></li><li><a href="/pages/d715cf/" class="sidebar-link">Centos7安装Elasticsearch 8.6.2</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>快速上手</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/10bfa2/" class="sidebar-link">一键部署</a></li><li><a href="/pages/10bfa7/" class="sidebar-link">项目启动</a></li><li><a href="/pages/192acb/" class="sidebar-link">API网关</a></li><li><a href="/pages/36da89/" class="sidebar-link">认证授权</a></li><li><a href="/pages/10bfa8/" aria-current="page" class="active sidebar-link">SSL证书</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#什么是ssl" class="sidebar-link">什么是SSL？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#什么是tls" class="sidebar-link">什么是TLS？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#为什么企业和web应用程序应该使用tls协议" class="sidebar-link">为什么企业和web应用程序应该使用TLS协议？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#ssl-tls如何工作" class="sidebar-link">SSL/TLS如何工作？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#什么是http-什么是https" class="sidebar-link">什么是HTTP？什么是HTTPS？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#为什么https安全" class="sidebar-link">为什么HTTPS安全？</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#keytool命令详解" class="sidebar-link">keytool命令详解</a></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#ssl证书在微服务的应用" class="sidebar-link">SSL证书在微服务的应用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#如何配置在yaml" class="sidebar-link">如何配置在yaml？</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#服务间开启ssl-openfeign如何调用接口" class="sidebar-link">服务间开启ssl，openfeign如何调用接口？</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#查看-feignautoconfiguration-源码" class="sidebar-link">查看 FeignAutoConfiguration 源码</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#httpclient5访问https网站-绕过ssl单向认证" class="sidebar-link">httpclient5访问https网站，绕过ssl单向认证</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#nacos开启ssl-各个服务无法注册-使用cer" class="sidebar-link">nacos开启ssl，各个服务无法注册（使用cer）</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#配置cer" class="sidebar-link">配置cer</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#yaml配置" class="sidebar-link">yaml配置</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#spring-boot-admin开启ssl-各个服务无法注册" class="sidebar-link">spring-boot-admin开启ssl，各个服务无法注册</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#查看-springbootadminclientautoconfiguration-源码" class="sidebar-link">查看 SpringBootAdminClientAutoConfiguration 源码</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#重写自动装配代码" class="sidebar-link">重写自动装配代码</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#自动装配" class="sidebar-link">自动装配</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#移除自动装配" class="sidebar-link">移除自动装配</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#gateway对下游服务不信任" class="sidebar-link">gateway对下游服务不信任</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#如何开启http2" class="sidebar-link">如何开启http2？</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#什么是http2" class="sidebar-link">什么是http2？</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#http2开启条件" class="sidebar-link">http2开启条件</a></li><li class="sidebar-sub-header level4"><a href="/pages/10bfa8/#yaml配置-2" class="sidebar-link">yaml配置</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#浏览器安装证书-信任自签名的https" class="sidebar-link">浏览器安装证书，信任自签名的HTTPS</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#创建证书-带域名" class="sidebar-link">创建证书(带域名)</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#导出证书" class="sidebar-link">导出证书</a></li><li class="sidebar-sub-header level3"><a href="/pages/10bfa8/#导入浏览器" class="sidebar-link">导入浏览器</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/10bfa8/#参考资料" class="sidebar-link">参考资料</a></li></ul></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>指南</span></li><li data-v-06225672><span data-v-06225672>快速上手</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/KouShenhai" target="_blank" title="作者" class="beLink" data-v-06225672>KCloud-Platform-Alibaba</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-09-26</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">SSL证书<!----></h1>  <div class="theme-vdoing-content content__default"><p>你好呀，我的老朋友！我是老寇，欢迎来到老寇云平台！<br>
几天不见啦，我又来啦！</p> <h2 id="什么是ssl"><a href="#什么是ssl" class="header-anchor">#</a> 什么是SSL？</h2> <p>SSL全称为 Security Socket Layer（安全套接字层），它是一种加密安全协议。
它的诞生就是 为了确保 Internet通信中的隐私、身份验证和数据完整性。
SSL是TLS加密的前身。（现在使用的是TLS）</p> <h2 id="什么是tls"><a href="#什么是tls" class="header-anchor">#</a> 什么是TLS？</h2> <p>TLS全称为 Transport Layer Security（安全传输层），它也是一种加密安全协议，
可以为互联网通信提供私密性和数据完整性。实施TLS是构建安全web应用的一个标准实践。</p> <h2 id="为什么企业和web应用程序应该使用tls协议"><a href="#为什么企业和web应用程序应该使用tls协议" class="header-anchor">#</a> 为什么企业和web应用程序应该使用TLS协议？</h2> <p>TLS加密可以帮助web应用程序免受数据泄露和其他攻击，如今，受TLS保护的HTTPS是网站的标准做法。
（知识点补充：2018年发布的TLS1.3进一步提高了TLS的速度。TLS1.3中的TLS握手仅一次往返&lt;即来回通信&gt;
而不是以前的两次，将握手过程所需时间缩短了几毫秒。如果用户以前已连接过网站，TLS握手往返次数为0，
从而进一步加快了速度。）</p> <h2 id="ssl-tls如何工作"><a href="#ssl-tls如何工作" class="header-anchor">#</a> SSL/TLS如何工作？</h2> <ul><li>为了提高高度隐私，SSL会对通过Web传输的数据进行加密，这意味着，任何试图截取此数据的人都只会看到几乎无法解密的乱码字符。</li> <li>SSL在两个通道设备之间启动称为握手的身份验证过程，以确保两个设备确实是它们所声称的真实身份。</li> <li>SSL还对数据进行数字签名，以提供数据完整性，验证数据是否到达目标接收者之前被篡改过。</li></ul> <h2 id="什么是http-什么是https"><a href="#什么是http-什么是https" class="header-anchor">#</a> 什么是HTTP？什么是HTTPS？</h2> <ul><li><p>HTTP全称为 HyperText Transfer Protocol（超文本传输协议），它是一种用于网络传输数据的协议。（HTTP消息分为两种：请求和响应）（在OSI模型中，HTTP是第七层协议）</p></li> <li><p>HTTPS全称为 HyperText Transfer Protocol Secure（超文本传输安全协议），支持加密和验证的HTTP，对比HTTP，HTTPS使用TLS来加密，对请求和响应进行数字签名，提供对网站服务器的身份认证，保护交换数据的隐私和完整性。（通俗来说，HTTPS = HTTP + SSL）
<img src="/img/6/img_1.png"></p></li></ul> <h2 id="为什么https安全"><a href="#为什么https安全" class="header-anchor">#</a> 为什么HTTPS安全？</h2> <p>HTTP协议传输文本，是以明文形式发送的，监视连接的任何人都能读取它，因此，HTTP不安全，回到HTTPS，无法看到其真实内容，只有一堆随机字符</p> <h2 id="keytool命令详解"><a href="#keytool命令详解" class="header-anchor">#</a> keytool命令详解</h2> <p>1.生成pfx证书（.p12是pfx的新格式）</p> <div class="language-shell extra-class"><pre class="language-shell"><code>keytool <span class="token parameter variable">-genkey</span> 
       <span class="token parameter variable">-alias</span> laokou-register <span class="token comment"># 证书别名,不区分大小写</span>
       <span class="token parameter variable">-storetype</span> PKCS12 <span class="token comment"># 密钥库类型，常用类型有JKS、PKCS12</span>
       <span class="token parameter variable">-keyalg</span> RSA <span class="token comment"># 密钥算法，可选密钥算法：RSA\DSA，默认DSA</span>
       <span class="token parameter variable">-keysize</span> <span class="token number">2048</span> <span class="token comment"># 密钥长度（RSA=2048,DSA=2048）</span>
       <span class="token parameter variable">-keystore</span> scg-keystore.p12  <span class="token comment"># 密钥库文件名称</span>
       <span class="token parameter variable">-validity</span> <span class="token number">3650</span> <span class="token comment"># 证书有效天数</span>
</code></pre></div><p>2.导出证书为cer（cer/crt是证书的公钥格式，cer是crt证书的微软形式）</p> <div class="language-shell extra-class"><pre class="language-shell"><code>keytool <span class="token parameter variable">-exportcert</span> <span class="token parameter variable">-v</span> 
        <span class="token parameter variable">-alias</span> laokou-register <span class="token comment"># 证书别名,不区分大小写</span>
        <span class="token parameter variable">-keystore</span> scg-keystore.p12  <span class="token comment"># 密钥库文件名称</span>
        <span class="token parameter variable">-storepass</span> laokou <span class="token comment"># 密钥库口令，推荐与keypass一致（获取keystore信息所需要密码）</span>
        <span class="token parameter variable">-file</span> register.cer <span class="token comment"># 导出的文件名</span>
</code></pre></div><h2 id="ssl证书在微服务的应用"><a href="#ssl证书在微服务的应用" class="header-anchor">#</a> SSL证书在微服务的应用</h2> <h3 id="如何配置在yaml"><a href="#如何配置在yaml" class="header-anchor">#</a> 如何配置在yaml？</h3> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">ssl</span><span class="token punctuation">:</span>
    <span class="token comment"># 开启证书,true开启ssl  false关闭ssl</span>
    <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span> 
    <span class="token comment"># 证书位置(放在resource即可)（证书就是我上面写的命令来生成的）</span>
    <span class="token key atrule">key-store</span><span class="token punctuation">:</span> classpath<span class="token punctuation">:</span>scg<span class="token punctuation">-</span>keystore.p12
    <span class="token comment"># 证书别名</span>
    <span class="token key atrule">key-alias</span><span class="token punctuation">:</span> laokou<span class="token punctuation">-</span>register
    <span class="token comment"># 秘钥类型</span>
    <span class="token key atrule">key-store-type</span><span class="token punctuation">:</span> PKCS12
    <span class="token comment"># 证书密码</span>
    <span class="token key atrule">key-store-password</span><span class="token punctuation">:</span> laokou
</code></pre></div><h3 id="服务间开启ssl-openfeign如何调用接口"><a href="#服务间开启ssl-openfeign如何调用接口" class="header-anchor">#</a> 服务间开启ssl，openfeign如何调用接口？</h3> <h4 id="查看-feignautoconfiguration-源码"><a href="#查看-feignautoconfiguration-源码" class="header-anchor">#</a> 查看 FeignAutoConfiguration 源码</h4> <p>话不多说，给我怼源码（作者使用的okhttp，httpclient类似）<br> <img src="/img/6/img.png"> <img src="/img/6/img_2.png"></p> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">spirng</span><span class="token punctuation">:</span>
    <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
      <span class="token key atrule">openfeign</span><span class="token punctuation">:</span>
        <span class="token key atrule">okhttp</span><span class="token punctuation">:</span>
          <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
        <span class="token key atrule">httpclient</span><span class="token punctuation">:</span>
          <span class="token comment"># 把disableSslValidationi设为true，就可以绕过ssl</span>
          <span class="token key atrule">disable-ssl-validation</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
</code></pre></div><h3 id="httpclient5访问https网站-绕过ssl单向认证"><a href="#httpclient5访问https网站-绕过ssl单向认证" class="header-anchor">#</a> httpclient5访问https网站，绕过ssl单向认证</h3> <p>把 FeignAutoConfiguration 代码搬过来（嘿嘿，效率为王）</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HttpUtil</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 创建HttpClient对象</span>
        <span class="token class-name">HttpClientBuilder</span> httpClientBuilder <span class="token operator">=</span> <span class="token class-name">HttpClientBuilder</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">boolean</span> disableSsl <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>disableSsl<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">disableSsl</span><span class="token punctuation">(</span>httpClientBuilder<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">disableSsl</span><span class="token punctuation">(</span><span class="token class-name">HttpClientBuilder</span> builder<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// X.509是密码学里公钥证书的格式标准，作为证书标准</span>
        <span class="token class-name">X509TrustManager</span> disabledTrustManager <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DisableValidationTrustManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 信任库</span>
        <span class="token class-name">TrustManager</span><span class="token punctuation">[</span><span class="token punctuation">]</span> trustManagers <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TrustManager</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">{</span> disabledTrustManager <span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token comment">// 怎么选择加密协议，请看 ProtocolVersion</span>
        <span class="token comment">// 为什么能找到对应的加密协议 请查看 SSLContextSpi</span>
        <span class="token class-name">SSLContext</span> sslContext <span class="token operator">=</span> <span class="token class-name">SSLContext</span><span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token constant">TLS_PROTOCOL_VERSION</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sslContext<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> trustManagers<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">SecureRandom</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">SSLConnectionSocketFactory</span> sslConnectionSocketFactory <span class="token operator">=</span> <span class="token class-name">SSLConnectionSocketFactoryBuilder</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setSslContext</span><span class="token punctuation">(</span>sslContext<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setHostnameVerifier</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">TrustAllHostnames</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">PoolingHttpClientConnectionManager</span> poolingHttpClientConnectionManager <span class="token operator">=</span> <span class="token class-name">PoolingHttpClientConnectionManagerBuilder</span>
                <span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setSSLSocketFactory</span><span class="token punctuation">(</span>sslConnectionSocketFactory<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        builder<span class="token punctuation">.</span><span class="token function">setConnectionManager</span><span class="token punctuation">(</span>poolingHttpClientConnectionManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">DisableValidationTrustManager</span> <span class="token keyword">implements</span> <span class="token class-name">X509TrustManager</span> <span class="token punctuation">{</span>
        <span class="token class-name">DisableValidationTrustManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">checkClientTrusted</span><span class="token punctuation">(</span><span class="token class-name">X509Certificate</span><span class="token punctuation">[</span><span class="token punctuation">]</span> x509Certificates<span class="token punctuation">,</span> <span class="token class-name">String</span> s<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">checkServerTrusted</span><span class="token punctuation">(</span><span class="token class-name">X509Certificate</span><span class="token punctuation">[</span><span class="token punctuation">]</span> x509Certificates<span class="token punctuation">,</span> <span class="token class-name">String</span> s<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">public</span> <span class="token class-name">X509Certificate</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">getAcceptedIssuers</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">X509Certificate</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">TrustAllHostnames</span> <span class="token keyword">implements</span> <span class="token class-name">HostnameVerifier</span> <span class="token punctuation">{</span>
        <span class="token class-name">TrustAllHostnames</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">verify</span><span class="token punctuation">(</span><span class="token class-name">String</span> s<span class="token punctuation">,</span> <span class="token class-name">SSLSession</span> sslSession<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="nacos开启ssl-各个服务无法注册-使用cer"><a href="#nacos开启ssl-各个服务无法注册-使用cer" class="header-anchor">#</a> nacos开启ssl，各个服务无法注册（使用cer）</h3> <p>查看issue <a href="https://github.com/alibaba/nacos/pull/3654" target="_blank" rel="noopener noreferrer">nacos支持https<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h4 id="配置cer"><a href="#配置cer" class="header-anchor">#</a> 配置cer</h4> <div class="language-shell extra-class"><pre class="language-shell"><code>		// https://github.com/alibaba/nacos/pull/3654
		// 请查看 HttpLoginProcessor
		System.setProperty<span class="token punctuation">(</span>TlsSystemConfig.TLS_ENABLE, TRUE<span class="token punctuation">)</span><span class="token punctuation">;</span>
		System.setProperty<span class="token punctuation">(</span>TlsSystemConfig.CLIENT_AUTH, TRUE<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment"># 确保文件位置填写正确</span>
		System.setProperty<span class="token punctuation">(</span>TlsSystemConfig.CLIENT_TRUST_CERT, <span class="token string">&quot;tls/register.cer&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h4 id="yaml配置"><a href="#yaml配置" class="header-anchor">#</a> yaml配置</h4> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token comment"># nacos使用https和http协议，只要注册临时服务，都是走RPC,因此使用https需要改为https</span>
<span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token comment"># nacos</span>
    <span class="token key atrule">nacos</span><span class="token punctuation">:</span>
      <span class="token key atrule">discovery</span><span class="token punctuation">:</span>
        <span class="token key atrule">server-addr</span><span class="token punctuation">:</span> https<span class="token punctuation">:</span>//127.0.0.1<span class="token punctuation">:</span><span class="token number">8848</span>
        <span class="token key atrule">namespace</span><span class="token punctuation">:</span> public
        <span class="token key atrule">username</span><span class="token punctuation">:</span> nacos
        <span class="token key atrule">password</span><span class="token punctuation">:</span> nacos
        <span class="token key atrule">group</span><span class="token punctuation">:</span> LAOKOU_GROUP
        <span class="token comment"># https</span>
        <span class="token key atrule">secure</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
        <span class="token comment"># true 临时 false 持久</span>
        <span class="token key atrule">ephemeral</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
      <span class="token key atrule">config</span><span class="token punctuation">:</span>
        <span class="token key atrule">server-addr</span><span class="token punctuation">:</span> https<span class="token punctuation">:</span>//127.0.0.1<span class="token punctuation">:</span><span class="token number">8848</span>
        <span class="token key atrule">namespace</span><span class="token punctuation">:</span> public
        <span class="token key atrule">username</span><span class="token punctuation">:</span> nacos
        <span class="token key atrule">password</span><span class="token punctuation">:</span> nacos
        <span class="token comment"># https://github.com/alibaba/spring-cloud-alibaba/blob/2021.x/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc</span>
        <span class="token comment"># 指定读取的文件格式</span>
        <span class="token key atrule">file-extension</span><span class="token punctuation">:</span> yaml
        <span class="token key atrule">group</span><span class="token punctuation">:</span> LAOKOU_GROUP
        <span class="token key atrule">refresh-enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
</code></pre></div><h3 id="spring-boot-admin开启ssl-各个服务无法注册"><a href="#spring-boot-admin开启ssl-各个服务无法注册" class="header-anchor">#</a> spring-boot-admin开启ssl，各个服务无法注册</h3> <h4 id="查看-springbootadminclientautoconfiguration-源码"><a href="#查看-springbootadminclientautoconfiguration-源码" class="header-anchor">#</a> 查看 SpringBootAdminClientAutoConfiguration 源码</h4> <p>话不多说，给我怼源码<br> <img src="/img/6/img_3.png"></p> <h4 id="重写自动装配代码"><a href="#重写自动装配代码" class="header-anchor">#</a> 重写自动装配代码</h4> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@ComponentScan</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;org.laokou.common.monitor&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Configuration</span><span class="token punctuation">(</span>proxyBeanMethods <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@ConditionalOnWebApplication</span>
<span class="token annotation punctuation">@AutoConfiguration</span>
<span class="token annotation punctuation">@Conditional</span><span class="token punctuation">(</span><span class="token class-name">SpringBootAdminClientEnabledCondition</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@AutoConfigureAfter</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token class-name">WebEndpointAutoConfiguration</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token class-name">RestTemplateAutoConfiguration</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span>
		<span class="token class-name">WebClientAutoConfiguration</span><span class="token punctuation">.</span><span class="token keyword">class</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@EnableConfigurationProperties</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token class-name">ClientProperties</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token class-name">InstanceProperties</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token class-name">ServerProperties</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span>
		<span class="token class-name">ManagementServerProperties</span><span class="token punctuation">.</span><span class="token keyword">class</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SpringBootAdminClientAutoConfig</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Configuration</span><span class="token punctuation">(</span>proxyBeanMethods <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@ConditionalOnBean</span><span class="token punctuation">(</span><span class="token class-name">RestTemplateBuilder</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">BlockingRegistrationClientConfig</span> <span class="token punctuation">{</span>

        <span class="token comment">/**
         * 阻塞
         */</span>
        <span class="token annotation punctuation">@Bean</span>
        <span class="token annotation punctuation">@ConditionalOnMissingBean</span>
        <span class="token keyword">public</span> <span class="token class-name">RegistrationClient</span> <span class="token function">registrationClient</span><span class="token punctuation">(</span><span class="token class-name">ClientProperties</span> client<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">RestTemplateBuilder</span> builder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RestTemplateBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setConnectTimeout</span><span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getConnectTimeout</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            builder<span class="token punctuation">.</span><span class="token function">setReadTimeout</span><span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getReadTimeout</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> client<span class="token punctuation">.</span><span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                builder <span class="token operator">=</span> builder<span class="token punctuation">.</span><span class="token function">basicAuthentication</span><span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> client<span class="token punctuation">.</span><span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">RestTemplate</span> build <span class="token operator">=</span> builder<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">HttpClientBuilder</span> httpClientBuilder <span class="token operator">=</span> <span class="token class-name">HttpClientBuilder</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 直接使用我上面写的</span>
            <span class="token class-name">HttpUtil</span><span class="token punctuation">.</span><span class="token function">disableSsl</span><span class="token punctuation">(</span>httpClientBuilder<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">CloseableHttpClient</span> closeableHttpClient <span class="token operator">=</span> httpClientBuilder<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">HttpComponentsClientHttpRequestFactory</span> requestFactory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HttpComponentsClientHttpRequestFactory</span><span class="token punctuation">(</span>
                    closeableHttpClient<span class="token punctuation">)</span><span class="token punctuation">;</span>
            build<span class="token punctuation">.</span><span class="token function">setRequestFactory</span><span class="token punctuation">(</span>requestFactory<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">BlockingRegistrationClient</span><span class="token punctuation">(</span>build<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token annotation punctuation">@Configuration</span><span class="token punctuation">(</span>proxyBeanMethods <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@ConditionalOnBean</span><span class="token punctuation">(</span><span class="token class-name">WebClient<span class="token punctuation">.</span>Builder</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@ConditionalOnMissingBean</span><span class="token punctuation">(</span><span class="token class-name">RestTemplateBuilder</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">ReactiveRegistrationClientConfig</span> <span class="token punctuation">{</span>
        <span class="token comment">/**
         * 响应式
         */</span>
        <span class="token annotation punctuation">@Bean</span>
        <span class="token annotation punctuation">@ConditionalOnMissingBean</span>
        <span class="token keyword">public</span> <span class="token class-name">RegistrationClient</span> <span class="token function">registrationClient</span><span class="token punctuation">(</span><span class="token class-name">ClientProperties</span> client<span class="token punctuation">,</span> <span class="token class-name">WebClient<span class="token punctuation">.</span>Builder</span> webClient<span class="token punctuation">)</span>
                <span class="token keyword">throws</span> <span class="token class-name">SSLException</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> client<span class="token punctuation">.</span><span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                webClient <span class="token operator">=</span> webClient<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token function">basicAuthentication</span><span class="token punctuation">(</span>client<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> client<span class="token punctuation">.</span><span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">SslContext</span> context <span class="token operator">=</span> <span class="token class-name">SslContextBuilder</span><span class="token punctuation">.</span><span class="token function">forClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trustManager</span><span class="token punctuation">(</span><span class="token class-name">InsecureTrustManagerFactory</span><span class="token punctuation">.</span><span class="token constant">INSTANCE</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">HttpClient</span> httpClient <span class="token operator">=</span> <span class="token class-name">HttpClient</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">secure</span><span class="token punctuation">(</span>t <span class="token operator">-&gt;</span> t<span class="token punctuation">.</span><span class="token function">sslContext</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            webClient<span class="token punctuation">.</span><span class="token function">clientConnector</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ReactorClientHttpConnector</span><span class="token punctuation">(</span>httpClient<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ReactiveRegistrationClient</span><span class="token punctuation">(</span>webClient<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> client<span class="token punctuation">.</span><span class="token function">getReadTimeout</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h4 id="自动装配"><a href="#自动装配" class="header-anchor">#</a> 自动装配</h4> <img src="/img/6/img_4.png"> <h4 id="移除自动装配"><a href="#移除自动装配" class="header-anchor">#</a> 移除自动装配</h4> <div class="language-shell extra-class"><pre class="language-shell"><code>@SpringBootApplication<span class="token punctuation">(</span>exclude <span class="token operator">=</span> <span class="token punctuation">{</span> SpringBootAdminClientAutoConfiguration.class <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="gateway对下游服务不信任"><a href="#gateway对下游服务不信任" class="header-anchor">#</a> gateway对下游服务不信任</h3> <p>查看spring官方文档 <a href="https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#tls-and-ssl" target="_blank" rel="noopener noreferrer">Gateway TLS 和 SSL<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <img src="/img/6/img_5.png"></p> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token key atrule">gateway</span><span class="token punctuation">:</span>
      <span class="token key atrule">httpclient</span><span class="token punctuation">:</span>
        <span class="token key atrule">ssl</span><span class="token punctuation">:</span>
          <span class="token key atrule">useInsecureTrustManager</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
</code></pre></div><h3 id="如何开启http2"><a href="#如何开启http2" class="header-anchor">#</a> 如何开启http2？</h3> <h4 id="什么是http2"><a href="#什么是http2" class="header-anchor">#</a> 什么是http2？</h4> <p>HTTP/2是一种网络协议，是HTTP/1.1的升级版，为了提高web性能，减少延迟，增加安全性，使web应用更加快速，高效和可靠</p> <h4 id="http2开启条件"><a href="#http2开启条件" class="header-anchor">#</a> http2开启条件</h4> <p>开启条件，就是必须使用ssl证书才行，因此有上面的铺垫，我们可以很轻松的开启</p> <h4 id="yaml配置-2"><a href="#yaml配置-2" class="header-anchor">#</a> yaml配置</h4> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">http2</span><span class="token punctuation">:</span>
    <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
</code></pre></div><p>补充一句，目前只限于tomcat和undertow</p> <h2 id="浏览器安装证书-信任自签名的https"><a href="#浏览器安装证书-信任自签名的https" class="header-anchor">#</a> 浏览器安装证书，信任自签名的HTTPS</h2> <h3 id="创建证书-带域名"><a href="#创建证书-带域名" class="header-anchor">#</a> 创建证书(带域名)</h3> <div class="language-shell extra-class"><pre class="language-shell"><code>keytool <span class="token parameter variable">-genkey</span> 
          <span class="token parameter variable">-alias</span> laokou-cert <span class="token comment"># 证书别名,不区分大小写</span>
          <span class="token parameter variable">-storetype</span> PKCS12 <span class="token comment"># 密钥库类型，可用类型：JKS,PKCS12</span>
          <span class="token parameter variable">-keyalg</span> RSA <span class="token comment"># 密钥的算法，如RSA,DSA,默认DSA</span>
          <span class="token parameter variable">-keysize</span> <span class="token number">2048</span> <span class="token comment"># 密钥长度（RSA=2048,DSA=2048）</span>
          <span class="token parameter variable">-keystore</span> scg-keystore.p12 密钥库文件名称
          <span class="token parameter variable">-validity</span> <span class="token number">3650</span> <span class="token comment"># 有效期天数</span>
          <span class="token parameter variable">-dname</span> <span class="token string">&quot;CN=127.0.0.1,OU=laokouyun,O=laokouyun,L=Shenzhen,ST=Guangzhou,C=CN&quot;</span> <span class="token comment"># 发行者信息（CN必填）</span>
          <span class="token parameter variable">-storepass</span> laokou <span class="token comment"># 密钥库口令</span>
          <span class="token parameter variable">-keypass</span> laokou <span class="token comment"># 私钥密码</span>
<span class="token comment"># 解释：-dname 构成</span>
<span class="token comment"># CN = 域名或IP，必填，CN要和服务器的域名或IP保持一致</span>
<span class="token comment"># OU = 组织单位名称</span>
<span class="token comment"># O = 组织名称</span>
<span class="token comment"># L = 城市或区域名称</span>
<span class="token comment"># ST = 州或省份名称</span>
<span class="token comment"># C = 国家简写（CN代表中国）</span>
</code></pre></div><h3 id="导出证书"><a href="#导出证书" class="header-anchor">#</a> 导出证书</h3> <div class="language-shell extra-class"><pre class="language-shell"><code>keytool <span class="token parameter variable">-exportcert</span> <span class="token parameter variable">-v</span> 
        <span class="token parameter variable">-alias</span> laokou-cert <span class="token comment"># 证书别名，不区分大小写 </span>
        <span class="token parameter variable">-keystore</span> scg-keystore.p12 <span class="token comment"># 密钥库文件名称</span>
        <span class="token parameter variable">-storepass</span> laokou <span class="token comment"># 密钥库口令</span>
        <span class="token parameter variable">-file</span> cert.cer <span class="token comment"># 证书名称</span>
</code></pre></div><h3 id="导入浏览器"><a href="#导入浏览器" class="header-anchor">#</a> 导入浏览器</h3> <ol><li>打开浏览器，找到证书管理（略）</li> <li>然后点下一步，直到完成导入（略）<br> <img src="/img/6/img_6.png"><br> <img src="/img/6/img_7.png"></li></ol> <p>我是老寇，我们下次再见啦！</p> <h2 id="参考资料"><a href="#参考资料" class="header-anchor">#</a> 参考资料</h2> <p><a href="https://www.cloudflare.com/zh-cn/learning/ssl/transport-layer-security-tls" target="_blank" rel="noopener noreferrer">SSL和TLS<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a><br> <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html" target="_blank" rel="noopener noreferrer">keytool文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a><br> <a href="https://www.cnblogs.com/librarookie/p/16364384.html" target="_blank" rel="noopener noreferrer">Keytool 工具的介绍与使用<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/09/26, 11:24:31</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/36da89/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">认证授权</div></a> <!----></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/36da89/" class="prev">认证授权</a></span> <!----></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="mailto:2413176044@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/KouShenhai" title="GitHub" target="_blank" class="iconfont icon-github"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2022-2023
    <span>laokou | Apache 2.0 License</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.c1130a26.js" defer></script><script src="/assets/js/2.4ec61f8d.js" defer></script><script src="/assets/js/17.f10e7f0d.js" defer></script>
  </body>
</html>
